<?php
namespace common\components\extenders;

use common\components\helpers\Fun;
use yii\base\component;
use Yii;
use common\models\datas\PositionInfo;
use common\models\datas\Album;
use common\models\datas\Medias;

class PositionGet extends component
{

	public function init(){}
    public static function get($key = '', $type)
    {
        $branch = Fun::getSiteId();
        $advert_data = [];
        $position_info = PositionInfo::find()->joinWith(['position'])->where(['branch_id' => $branch, 'type' => $type, '{{%position}}.position_key' => $key])->one();
        //var_dump($position_info);die;
        if($position_info==null){
            $position_info = PositionInfo::find()->joinWith(['position'])->where(['branch_id' =>'2', 'type' => $type, '{{%position}}.position_key' => $key])->one();
        }//现在是如果是空的话，就获取的是青岛李沧奥克斯的分店图片
//        if (!is_object($position_info)) return null;
        if ($position_info->type == 0) { //文本内容
            $advert_data = isset($position_info->info) ? $position_info->info : null;
        }
        if ($position_info->type == 1) { //广告图片
            //$advert_data = Album::find()->select('file_path')->where(['branch_id' => $branch, 'object_id' => $position_info->id])->asArray()->column();之前用的表
            $advert_data=Medias::find()->select('file_path')->where(['object_id' => $position_info->id])->asArray()->column();//新的放图片的表
        }
        if ($position_info->type == 2) { //小部件

        }
        return $advert_data;
    }

}